<?
$page = "modelos";
if ($_GET['id']) {
    $data = ModelosControl::Select((int)$_GET['id']);
}
?>
<div class="container-form">
    <h1>Modelos de Automóveis</h1>
    <form action="<?= __ADMIN_URI__; ?>actions/<?= $page ?>.php" method="post" enctype="multipart/form-data" id="form-cadastre" onsubmit="return Validation();">
        <input type="hidden" name="redirect" id="redirect" value="<?= __ADMIN_URI__ . $page ?>">
        <input type="hidden" name="id" id="codigo" value="<?= $data[0]['id']; ?>">
        <div class="input">
            Nome: <input type="text" name="name" id="name" value="<?= $data[0]['name']; ?>" class="required" size="50">
            Tipo:
            <select name="id_type" id="id_type" class="required">
                <option value="">--Selecione o Tipo</option>
                <?
                $type = TiposControl::Listar();
                if (isset($type)) {
                    foreach ($type as $list_type) {
                        ?>
                <option value="<?=$list_type['id'];?>" <? if($data[0]['id_type']==$list_type['id']){ ?> selected="selected" <?}?>><?=$list_type['name'];?></option>
                    <? }
                } ?>
            </select>
            Marca:
            <select name="id_brand" id="id_brand" class="required">
                <option value="">--Selecione o Marca</option>
                <?
                $brand = MarcasControl::Listar();
                if (isset($brand)) {
                    foreach ($brand as $list_brand) {
                        ?>
                <option value="<?=$list_brand['id'];?>" <? if($data[0]['id_brand']==$list_brand['id']){ ?> selected="selected" <? } ?>><?=$list_brand['name'];?></option>
                    <? }
                } ?>
            </select>
        </div>
        <div class="input">
            <input type="submit" value="Salvar">
            <input type="button" value="Novo" onclick="location.href = $('#redirect').val();">
        </div>
    </form>
    <hr>
    <div class="list">
        <div class="list-data">
            <ul>
                <li>Cód</li>
                <li>Nome</li>
                <li>Opções</li>
            </ul>
            <?php
            foreach (ModelosControl::Listar() as $list) {
                $urldelete = __ADMIN_URI__ . "actions/" . $page . ".php?id=" . $list['id'] . "&redirect=" . __ADMIN_URI__ . $page;
                ?>
                <ul>
                    <li><?= $list['id']; ?></li>
                    <li><?= $list['name']; ?></li>
                    <li><a href="<?= __ADMIN_URI__ . $page ?>/<?= $list['id']; ?>">Editar</a> | <a href="javascript:ApagarRegistro('<?= $urldelete ?>')">Excluir</a></li>
                </ul>
                <?
            }
            ?>

        </div>
    </div>
</div>

